//============================================================================
// Name        : MultiHopLeach.cpp

//============================================================================

#include <iostream>
#include <cstdlib>

#include "Include.h"
int main(int nArgc, char* argv[])
{
	int nRoundCount = nMaxRoundcount;
	if (nArgc > 1)
	{
		nRoundCount = atoi(argv[1]);
	}
	cout << "Starting Simulation of Multi-Hop LEACH " << argv[0] << endl;
	double power = 0;
	int nNodeCount = nMaxSensorCount;

	Field oField(nMaxLen, nMaxWidth);
	{
		power = dMaxSinkPower;
		Coordinate coord(25, 25);
		Sink sink1(101, power, coord);
		oField.AddSink(sink1);
	}
	{
		power = dMaxSinkPower;
		Coordinate coord(75, 25);
		Sink sink2(102, power, coord);
		oField.AddSink(sink2);
	}

	double x = 0, y = 0;
	double dQtrLen = nMaxLen / 2;
	double dQtrWidth = nMaxWidth / 2;
	int i = 0;
	for (x = 0; x < nMaxLen; x += dQtrLen)
	{
		for (y = 0; y < nMaxWidth; y += dQtrWidth)
		{
			Coordinate qCoord(x, y); //Q1 0,0 //Q2 50,0
			Quarter quarter(i++, dQtrLen, dQtrWidth, qCoord);
			oField.AddQuarter(quarter);
		}
	}

	x = 0, y = 0;
	power = Einit;
	cout.precision(15);
	srand(time(NULL));
	for (int i = 0; i < nNodeCount; ++i)
	{
		x = rand() % oField.GetLength();
		y = rand() % oField.GetWidth();
		Coordinate coord(x, y);
		Sensor sensor(i, power, coord);
		oField.AddSensor(sensor);
		cout << sensor;
	}

	cout << oField;
	cout << "Starting Simulation " << endl;
	int nRunCnt = oField.MultiHopIteration(nRoundCount);
	cout << "Total Round                    " << fixed << nRunCnt << endl;

	cout.precision(12);

	NodeContainer::DebugPrint();
	NodeContainer::Cleanup();
	cout << endl << endl;
	cout << "Input Parameters" << endl;
	cout << "Number of the sensor nodes (N)                 " << nNodeCount
			<< endl;
	cout << "Initial energy of the sensor nodes (Einit)     " << fixed << Einit
			<< endl;
	cout << "Length of the packet ( l )                     " << fixed
			<< DATA_MESSAGE_LENGTH << endl;

	cout << "Energy consumption on circuit (Eelec)          " << fixed << Eelec
			<< endl;
	cout << "Channel parameter in free-space model (Efs )   " << fixed << Efs
			<< endl;
	cout << "Data Aggregation Energy (EDA)                  " << fixed << EDA
			<< endl;
	cout << "Field                                          " << nMaxLen
			<< " * " << nMaxWidth << endl;

	return EXIT_SUCCESS;
}
